home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 6.6 KB | 253 lines | [TEXT/KAHL] |
- /***************************************************** IMPLEMENTATION
- DATE: 9/26/93
- AUTHOR: Eric R. Rosé
-
- CLASS: CPPPrefsWindow
-
- SUPERCLASS: CPPWindow
-
- This C++ class manages the NetApp preferences window
-
- ********************************************************************/
-
- #include "CPPPrefsWindow.h"
- #include <CPPWindowManager.h>
- #include <CPPButton.h>
- #include <CPPCheckBox.h>
- #include <CPPStaticText.h>
- #include <CPPIntText.h>
- #include <ToolboxTools.h>
-
- #define prefsWindowID 202
-
- extern CPPWindowManager *gWindowManager;
- extern void DoStdOKButton (CPPWindow *theWindow);
- extern void DoStdCancelButton (CPPWindow *theWindow);
-
- /*-----------------------------------------------------------------*/
-
- void DoScanClick (CPPWindow *theWindow)
- /* If the checkbox is unchecked, set the value of 'scan' to 0 */
- /* Otherwise, set it to a default value */
- {
- CPPPrefsWindow *ourWindow = (CPPPrefsWindow *)theWindow;
-
- if (ourWindow)
- {
- if (ourWindow->doScan->GetValue())
- {
- ourWindow->scanRate->MakeVisible(TRUE);
- ourWindow->MakeTarget(ourWindow->scanRate);
- }
- else
- {
- if (ourWindow->GetTarget() == ourWindow->scanRate)
- if (!ourWindow->MakeNextTarget())
- ourWindow->MakeTarget (NULL);
- ourWindow->scanRate->MakeVisible(FALSE);
- }
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void DoConfirmClick (CPPWindow *theWindow)
- /* If the checkbox is unchecked, set the value of 'confirm' to 0 */
- /* Otherwise, set it to a default value */
- {
- CPPPrefsWindow *ourWindow = (CPPPrefsWindow *)theWindow;
-
- if (ourWindow)
- {
- if (ourWindow->doConfirm->GetValue())
- {
- ourWindow->confirmRate->MakeVisible(TRUE);
- ourWindow->MakeTarget(ourWindow->confirmRate);
- }
- else
- {
- if (ourWindow->GetTarget() == ourWindow->confirmRate)
- if (!ourWindow->MakeNextTarget())
- ourWindow->MakeTarget (NULL);
- ourWindow->confirmRate->MakeVisible(FALSE);
- }
- }
- }
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
- CPPPrefsWindow::CPPPrefsWindow (CPPWindowManager *theManager,
- PrefsData *initData) :
- CPPWindow (theManager, prefsWindowID)
- {
- GrafPtr SavePort;
- Rect tempRect;
- CPPStaticText *ST, *ST2;
-
- GetPort(&SavePort);
- SetPort(this->theWindow);
-
- // create static text items
- SetRect (&tempRect, 250, 62, 306, 78);
- ST2 = new CPPStaticText ((CPPWindow *)this, &tempRect, "\pminutes", systemFont, 12);
-
- SetRect (&tempRect, 235, 90, 291, 106);
- ST = new CPPStaticText ((CPPWindow *)this, &tempRect, "\pminutes", systemFont, 12);
-
- // create edit text areas
- SetRect (&tempRect, 221, 62, 249, 78);
- confirmRate = new CPPIntText ((CPPWindow *)this, &tempRect,
- initData->confirmRate,
- 2, systemFont, 12);
- if (!initData->confirmRate)
- confirmRate->MakeVisible(FALSE);
-
- SetRect (&tempRect, 206, 90, 234, 106);
- scanRate = new CPPIntText ((CPPWindow *)this, &tempRect,
- initData->scanRate, 2,
- systemFont, 12);
- if (!initData->scanRate)
- scanRate->MakeVisible(FALSE);
-
- // create the 'sound' checkboxes
- playMessage = new CPPCheckBox ((CPPWindow *)this, 129,
- initData->playMessage, FALSE);
- playLogon = new CPPCheckBox ((CPPWindow *)this, 135,
- initData->playLogon, FALSE);
-
- // create the 'scan' checkboxes and edit areas
- doScan = new CPPCheckBox ((CPPWindow *)this, 131,
- (initData->scanRate != 0),
- FALSE);
- doScan->SetDoClickProc (DoScanClick);
-
- doConfirm = new CPPCheckBox ((CPPWindow *)this, 130,
- (initData->confirmRate != 0),
- FALSE);
- doConfirm->SetDoClickProc (DoConfirmClick);
-
-
- // create the dialog buttons
- okButton = new CPPButton ((CPPWindow *)this, 133, TRUE);
- okButton->SetDoClickProc (DoStdOKButton);
-
- cancelButton = new CPPButton ((CPPWindow *)this, 134, FALSE);
- cancelButton->SetDoClickProc (DoStdCancelButton);
-
- SetRect (&tempRect, 250, 62, 306, 78);
-
- this->MakeNextTarget ();
-
- SetPort(SavePort);
-
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPPrefsWindow::~CPPPrefsWindow ()
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- char *CPPPrefsWindow::ClassName (void)
- {
- return "CPPPrefsWindow";
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPPrefsWindow::GetDialogData (PrefsData *theData)
- /* copy the data from the window into the provided structure */
- {
- if (theData)
- {
- theData->scanRate =
- doScan->GetValue() ? scanRate->GetAsInt() : 0;
-
- theData->confirmRate =
- doConfirm->GetValue() ? confirmRate->GetAsInt() : 0;
-
- if (playMessage->GetValue())
- theData->playMessage = TRUE;
- else
- theData->playMessage = FALSE;
-
- if (playLogon->GetValue())
- theData->playLogon = TRUE;
- else
- theData->playLogon = FALSE;
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPPrefsWindow::DoUserKey (EventRecord *theEvent)
- {
- char theKey;
- CPPList *TempList;
-
- theKey = theEvent->message & charCodeMask;
- if (!(theEvent->modifiers & cmdKey))
- {
- switch (theKey) {
- case kTab :
- if (ShiftKeyDown(theEvent->modifiers))
- {MakePreviousTarget(); return TRUE;}
- else
- {MakeNextTarget(); return TRUE;}
- break;
- case kEscape :
- if (cancelButton)
- cancelButton->SimulateClick();
- return TRUE;
- break;
- case kEnter :
- if (okButton)
- okButton->SimulateClick();
- return TRUE;
- break;
- default:
- return CPPWindow::DoUserKey (theEvent);
- break;
- } // switch
- }
- else
- {
- if (theKey == '.')
- {
- if (cancelButton)
- cancelButton->SimulateClick();
- return TRUE;
- }
- else
- return CPPWindow::DoUserKey (theEvent);
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean DoPrefsWindow (PrefsData *initData)
- {
- CPPPrefsWindow *theWindow;
- Boolean theResult;
-
- theWindow = new CPPPrefsWindow (gWindowManager, initData);
-
- if (theWindow)
- {
- theWindow->DoModalWindow ();
- if ((theResult = theWindow->modalResult))
- theWindow->GetDialogData (initData);
- delete theWindow;
- return theResult;
- }
- else
- {
- ErrorAlert (MemError(), "\pCould not show the 'prefs' dialog");
- return FALSE;
- }
- }